{% extends "app/base_site.html" %}
{% block title %} {% if  "add" == handle %}添加{% else %}编辑{% endif %}轮巡 {% endblock title %}
{% block stylesheets %}
  {{ block.super }}
    <style>
    input[type="file"]{
      color: #8d2f2f;
      font-size: 12px;
    }
    ::file-selector-button{
      font-size: 12px;
      color: #fff;
      border-radius: 4px;
      border: 1px solid #2a80eb;
      padding: 2px 4px;
      background-color: #2a80eb;
      cursor: pointer;
    }

</style>
{% endblock stylesheets %}
{% block content %}

  <div class="right_col" role="main">
    <div class="">
      <div class="row">
        <div class="col-md-12 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
                <h2>{% if  "add" == handle %}添加{% else %}编辑{% endif %}轮巡 <span id="top_msg">{{top_msg}}</span></h2>
              <div class="clearfix"></div>
            </div>
            <div class="x_content">
              <br>
              <form class="form-horizontal form-label-left"  method="post" enctype="multipart/form-data" data-parsley-validate  >

                     <input type="hidden" name="handle"  value="{{ handle }}">
                     <input type="hidden" name="code"  value="{{ obj.code }}">
                     <input type="hidden" name="control_codes"  value="{{ obj.control_codes }}">

                <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">轮巡编号 </label>
                  <div class="col-md-3 col-sm-3 col-xs-12">
                     <input type="text"  value="{{ obj.code }}" class="form-control" disabled="disabled">
                  </div>
                </div>
               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">名称 <span class="required" style="color: red;">*</span></label>
              <div class="col-md-3 col-sm-3 col-xs-12">
                    <input type="text" name="name" value="{{ obj.name }}" required="required"  class="form-control">
                  </div>
                </div>

               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">布控 <span class="required" style="color: red;">*</span></label>
                    <div class="col-md-9 col-sm-9 col-xs-12">
                    <select id="control_codes" style="height: 200px;"  class="select2_multiple form-control" required="required"  multiple="multiple" >
                        <option value="0">---请选择布控(可多选)---</option>
                        {% for control in controls %}
                          <option value="{{ control.code }}" {% if 1 == control.is_selected %} selected {% endif %} >{{ control.id }} / {{ control.code }} 【 {{ control.stream_nickname }} / {{ control.flow_code }}】</option>
                         {% endfor %}
                    </select>
                  </div>
                </div>
                             <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">轮巡并发 <span class="required" style="color: red;">*</span></label>
              <div class="col-md-3 col-sm-3 col-xs-12">
                    <input type="number" name="control_concurrency" value="{{ obj.control_concurrency }}" required="required"  class="form-control">
                  </div>
                </div>

               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">轮巡时长（秒） <span class="required" style="color: red;">*</span></label>
              <div class="col-md-3 col-sm-3 col-xs-12">
                    <input type="number" name="control_duration" value="{{ obj.control_duration }}" required="required"  class="form-control">
                  </div>
                </div>

               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">预览刷新时长（秒） <span class="required" style="color: red;">*</span></label>
              <div class="col-md-3 col-sm-3 col-xs-12">
                    <input type="number" name="preview_refresh_duration" value="{{ obj.preview_refresh_duration }}" required="required"  class="form-control">
                  </div>
                </div>

                  <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">备注
                  </label>
                  <div class="col-md-9 col-sm-9 col-xs-12">
                    <textarea name="remark" class="form-control" rows="3" placeholder="">{{ obj.remark }}</textarea>
                  </div>
                </div>

                <div class="form-group">
                  <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                    <button type="button" onclick="window.history.go(-1)" class="btn btn-default">返回</button>
                    <button type="submit" class="btn btn-dark">提交</button>

                  </div>
                </div>

              </form>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
{% endblock content %}

{% block javascripts %}
  {{ block.super }}
<script>

let handle = "{{ handle }}";
let audio_code = "{{ obj.code }}";
let ele_input_name= $("input[name='name']");
let ele_input_control_codes = $("input[name='control_codes']");
let ele_select_control_codes = $("#control_codes");

$(document).ready(function () {
   $("form").submit(function () {
        if(ele_input_name.val().trim() === ""){
            myToast2025("请输入名称","error");
            return false;
        }

        let temp1 = ele_select_control_codes.val();//typeof object, array
        if(temp1===null){
            myToast2025("请至少选择1个布控","error");
            return false;
        }else{
            let temp2 = [];
            for (let i = 0; i < temp1.length; i++) {
                if("0"!==temp1[i]){
                    temp2.push(temp1[i]);
                }
            }
            if(temp2.length > 0){
                let control_codes = temp2.join(",");
                ele_input_control_codes.val(control_codes);
            }else{
                myToast2025("请至少选择1个布控","error");
                return false;
            }
        }

       if("add" === handle){
            //添加

       }else {
            //更新

       }

   });
});

</script>

{% endblock javascripts %}
